/**
 * 
 */
package self.vector.ding.dao.mybatis.generator.plugin;

import java.util.List;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.internal.util.StringUtility;

/**
 * @author vector
 *
 */
public class FileRenamePlugin extends PluginAdapter {
	
	private final String Pro_JavaMapper_FileSuffix = "javaMapperFileSuffix";
	private final String Pro_Example_FileSuffix = "exampleFileSuffix";
	private final String Pro_XmlMapper_FileSuffix = "xmlMapperFileSuffix";
	
	private final String OriginMapperFileSuffix = "Mapper";
	private final String OriginExampleFileSuffix = "Example";

	/* (non-Javadoc)
	 * @see org.mybatis.generator.api.Plugin#validate(java.util.List)
	 */
	public boolean validate(List<String> warnings) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.mybatis.generator.api.PluginAdapter#initialized(org.mybatis.generator.api.IntrospectedTable)
	 */
	@Override
	public void initialized(IntrospectedTable introspectedTable) {
		String mapperClassFileSuffix = context.getProperties().getProperty(Pro_JavaMapper_FileSuffix);
		if (StringUtility.stringHasValue(mapperClassFileSuffix)) {
			String javaMapperType = introspectedTable.getMyBatis3JavaMapperType();
			introspectedTable.setMyBatis3JavaMapperType(javaMapperType.replace(OriginMapperFileSuffix, mapperClassFileSuffix));
		}
		
		String exampleSuffix = context.getProperties().getProperty(Pro_Example_FileSuffix);
		if (StringUtility.stringHasValue(exampleSuffix)) {
			String exampleType = introspectedTable.getExampleType();
			introspectedTable.setExampleType(exampleType.replace(OriginExampleFileSuffix, exampleSuffix));
		}
		
		String xmlMapperSuffix = context.getProperties().getProperty(Pro_XmlMapper_FileSuffix);
		if (StringUtility.stringHasValue(xmlMapperSuffix)) {
			String xmlMapperType = introspectedTable.getMyBatis3XmlMapperFileName();
			introspectedTable.setMyBatis3XmlMapperFileName(xmlMapperType.replace(OriginMapperFileSuffix, xmlMapperSuffix));
		}
	}
	
}
